﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>CYQ.Data 网络应用示例</title>

	<script src="js/jquery-1.4.1.min.js" type="text/javascript"></script>

</head>
<body onload="loadData()">
	<form id="form1" runat="server">
		<div>
			直接读webservice<hr />
			<asp:GridView ID="gvUsers" runat="server"></asp:GridView>
			<hr />
			json 解析显示的内容：<hr />
			<div id="jsonBody" title="显示用的Div一个">	</div>
			<hr />
			<input id="txtJson" type="text" value=""  style="width: 300px" />
			<input type="button" value="提交更新" onclick="updateData()" />
		</div>
	</form>

	<script>
	//默认加载数据
		function loadData()
		{
		  $.ajax(
		  {
			  type:"Post",
			  url:"Service.asmx/GetUsersInfo",
			  success:function(result){
			  //解析成json,ie7下测试通过,firefox下返回的result是Docuemtn,则不能直取text
			  var json = eval('(' + result.text + ')');

			  $.each(json.data, function(i,row) {
			  $("#jsonBody").append("ID:" + row.ID + "---" + "UserName:" + row.UserName + "<br/>");  });
            }
		  });
		}
	   //默认提交数据
	    function updateData()
		{
		  $.ajax(
		  {
			  type:"Post",
			  url:"Service.asmx/UpdateUserInfo",
			  data:"json="+$('#txtJson').val(),
			  success:function(result){alert(result.text);location.href=location.href}
		  });
		}
	</script>

</body>
</html>
